<?php

CRequire('CObject');

class AuthKernel extends CObject {
	function &Authenticate($credentials) {
		CAbstract('AuthKernel::Authenticate()', $this);
	}
}

class AuthPack extends AuthKernel {
	function Init($items /*, ... */) {
		$a = func_get_args();
		foreach ($a as $class)
			$this->AddKernelOfClass($class);
	}
	
	var $_Kernels = array();
	function AddKernel(&$what) {
		$this->_Kernels[] = &$what;
	}
	function AddKernelOfClass($class) {
		$x = &new $class();
		$this->AddKernel($x);
	}
	
	function &Authenticate($credentials) {
		$errs = array();
		
		foreach ($this->_Kernels as $kernel) {
			$x = &$kernel->Authenticate($credentials);
			if (!CErr($x))
				return $x;
			else
				$errs[] = $x;
		}
		
		if (sizeof($errs) == 1)
			return $errs[0];
		else {
			$x = CError::MultipleErrors($errs);
			return $x;
		}
	}
}

?>